//
//  MCDietApi.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/23.
//

import Foundation
import Moya

enum MCDietApi {
    case dietLabelCategory
    case dietDetail(ids:String?)
    case dietPageList(current:Int?,labels:String?)
    case dietRecommandList(current:Int?,Labels:Int?,zhName:String?)
    //获取食材的类型
    case dietFoodCategory
    //食材分类的类型
    case dietFoodListPageList(current:Int?,labels:String?,foodType:Int?)
    //食材详情
    case foodDetail(ids:String)
    
}

extension MCDietApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .dietDetail:
            return "api/admin/diet/dietDetail"
        case .dietLabelCategory:
            return  "api/admin/diet/getDietLabel"
        case .dietPageList,.dietRecommandList:
            return "api/admin/diet/getDietPage"
        case .dietFoodCategory:
            return "api/admin/diet/getFoodType"
        case .dietFoodListPageList:
            return "api/admin/diet/getFoodPage"
        case .foodDetail:
            return "api/admin/diet/foodDetailForApp"
        }
    }
    var method:Moya.Method {
        switch self {
        case .dietDetail:
            return .get
        case .dietLabelCategory:
            return .get
        case .dietPageList,.dietRecommandList:
            return .get
        case .dietFoodCategory:
            return .get
        case .dietFoodListPageList:
            return .get
        case .foodDetail:
            return .get
            
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case let .dietDetail(ids):
            return .requestParameters(parameters: ["id":ids ?? ""], encoding: URLEncoding.default)
        case .dietLabelCategory:
            return .requestPlain
        case let .dietPageList(current, labels):
            
            var param:[String:Any] = ["current":current ?? 0,"size":20]
            if labels?.contains("0") == true {
                
            }else {
                param["label"] = labels
            }
            
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case let .dietRecommandList(current,Labels, zhName):
            
            var param:[String:Any] = ["current":current ?? 0,"size":20,"zhName":zhName ?? ""]
            if Labels == 0 {
                
            }else {
                param["label"] = Labels
                
            }
            
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .dietFoodCategory:
            return .requestPlain
            
        
        case let .dietFoodListPageList(current, labels, foodType):
            
            var param:[String:Any] = ["current":current ?? 0,"size":20, "foodType":foodType ?? 0]
            if labels?.isEmpty == true {
                
            }else {
                param["foodName"] = labels
                
            }
            
            return .requestParameters(parameters:param, encoding: URLEncoding.default)
            
        case let .foodDetail(ids):
            
            return .requestParameters(parameters: ["id":ids], encoding: URLEncoding.default)
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
    
}


